package com.xiaochi.practice.api.common;

import lombok.Getter;

/**
 * @author zqx
 * @since 2024/7/21
 */
@Getter
public enum ResultCodeEnum {

    SUCCESS(200,"成功"),
    FAIL(500,"失败"),
    UNAUTHORIZED(401,"未认证"),
    FORBIDDEN(403,"禁止访问"),
    NOT_FOUND(404,"未找到"),
    SERVER_ERROR(500,"服务器错误");

    private int code;
    private String message;

    ResultCodeEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ResultCodeEnum getResultCodeEnum(int code) {
        for (ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()) {
            if (resultCodeEnum.getCode() == code) {
                return resultCodeEnum;
            }
        }
        return null;
    }
}
